/*
 * this is the header file shared with userspace programms.
 */
#ifndef LCPD_SCOPE_USER
#define LCPD_SCOPE_USER

//define read errors
#define READ_ERROR_TIMEOUT -1
#define READ_ERROR_BUFFER_SIZE -2

// Bit define
#define D7 0x80
#define D6 0x40
#define D5 0x20
#define D4 0x10
#define D3 0x08
#define D2 0x04
#define D1 0x02
#define D0 0x01

// AD-CONVERTER REGISTER 0X00 
#define SPI_RESET 			D7					// resets all internal register and self-clears to 0
#define SPI_EXTREF 			(D6 | D5) 			// Enable external reference

// AD-CONVERTER REGISTER 0X20
#define SPI_LOW_SPEED 		D2					// LOW_SPEED mode: sampling frequency <= 100MPSP

// AD-CONVERTER REGISTER 0X3F
#define SPI_INTREF 			D5 					// Enable internal reference
#define SPI_EXTREF 			(D6 | D5) 			// Enable external reference
#define SPI_STANDBY			D1					// Both ADC channels are put in standby

// AD-CONVERTER REGISTER 0X40
#define SPI_PMODE_NORMAL 	D3
#define SPI_PMODE_DOWN_A 	(D3 | D2 | D1)
#define SPI_PMODE_DOWN_B 	(D3 | D2 | D0)

// AD-CONVERTER REGISTER 0X41
#define SPI_LVDS 				D7					//Enable LVDS interface

// AD-CONVERTER REGISTER 0X50
#define SPI_2S_COMP 			D2					//DATA FORMAT 2s complement
#define SPI_OFFSET_BIN 		(D2 |D1)				//DATA FORMAT Offset binary

// AD-CONVERTER REGISTER 0X53 (Channel A)
// &AD-CONVERTER REGISTER 0X66 (Channel B)
#define SPI_ENABLE_OFFS_CORR D6	// Enable Offset correlation

#define SPI_ADDR_CS 0x4024

// AD-CONVERTER REGISTER 0X62 (Channel A)
// &AD-CONVERTER REGISTER 0X75 (Channel B)
#define SPI_TEST_TOGGLE_PATTERNS (D1 | D0) 	// Test Patterns to verify data capture
#define SPI_TEST_RAMP_PATTERNS D2			// Test Patterns to verify data capture

#define IOCTL_SETSAMPLERATE 	_IOW(MAJOR_NUM, 1, short int)	// Set Samplerate (MIN_SAMPLING_RATE < Samplerate < MAX_SAMPLING_RATE)
#define IOCTL_SETBUFFERSIZE 	_IOW(MAJOR_NUM, 2, short int)	// Set Buffersize (MIN_BUFFER_SIZE < Buffersize < MAX_BUFFER_SIZE)
#define IOCTL_SETTRIGLEV_A 		_IOW(MAJOR_NUM, 3, short int)	// Set Trigger Level CHA (12 Bit-Wert)
#define IOCTL_SETVOLTLEV_A		_IOW(MAJOR_NUM, 4, short int)	// Set Voltage Level CHA (0 | 1 | 2 | 3)
#define IOCTL_SETTRIGLEV_B		_IOW(MAJOR_NUM, 5, short int)	// Set Trigger Level CHB (12 Bit-Wert)
#define IOCTL_SETVOLTLEV_B		_IOW(MAJOR_NUM, 6, short int)	// Set Voltage Level CHB (0 | 1 | 2 | 3)
#define IOCTL_ADRESET			_IOW(MAJOR_NUM, 20, short int)	// Resets ad-converter (SPI_RESET)
#define IOCTL_ADSPEED			_IOW(MAJOR_NUM, 21, short int)	// Set Speed (SPI_LOW_SPEED | ~SPI_LOW_SPEED)
#define IOCTL_ADREF				_IOW(MAJOR_NUM, 22, short int)	// Set Referenz Voltage (SPI_INTREF | SPI_EXTREF)
#define IOCTL_ADSTANDBY			_IOW(MAJOR_NUM, 23, short int)	// Set StandBy Mode (SPI_STANDBY | ~SPI_STANDBY)
#define IOCTL_ADPWDMODE			_IOW(MAJOR_NUM, 24, short int)	// Powerdown Modes (SPI_PMODE_NORMAL | SPI_PMODE_DOWN_A | SPI_PMODE_DOWN_B)
#define IOCTL_ADLVDSCOMOS		_IOW(MAJOR_NUM, 25, short int)	// Set Data Typ (SPI_2S_COMP | SPI_OFFSET_BIN)
#define IOCTL_ADDATAFORMAT		_IOW(MAJOR_NUM, 26, short int)	// Set Data Format (SPI_2S_COMP | SPI_OFFSET_BIN)
#define IOCTL_ADOFFCORR_A		_IOW(MAJOR_NUM, 27, short int)	// Set Offset Correlation CHA (SPI_ENABLE_OFFS_CORR | ~SPI_ENABLE_OFFS_CORR)
#define IOCTL_ADOFFCORR_B		_IOW(MAJOR_NUM, 28, short int)	// Set Offset Correlation CHB (SPI_ENABLE_OFFS_CORR | ~SPI_ENABLE_OFFS_CORR)
#define IOCTL_ADTSTPATTERN_A	_IOW(MAJOR_NUM, 29, short int)	// Set Test Pattern CHA (SPI_TEST_TOGGLE_PATTERNS | SPI_TEST_RAMP_PATTERNS)
#define IOCTL_ADTSTPATTERN_B	_IOW(MAJOR_NUM, 30, short int)	// Set Test Pattern CHB (SPI_TEST_TOGGLE_PATTERNS | SPI_TEST_RAMP_PATTERNS)

#define IOCTL_ERROR_RESET 			-20
#define IOCTL_ERROR_REF 			-21
#define IOCTL_ERROR_ADSPEED 		-22
#define IOCTL_ERROR_STANDBY 		-23
#define IOCTL_ERROR_POWERDOWNMODE 	-24
#define IOCTL_ERROR_LVDSCMOS 		-25
#define IOCTL_ERROR_DATAFORMAT 		-26
#define IOCTL_ERROR_OFFS_CORR 		-27
#define IOCTL_ERROR_TESTPATTERNS 	-28
#define IOCTL_ERROR_TRIGGER_LEVEL 	-29
#define IOCTL_ERROR_BUFFERSIZE 		-30
#define IOCTL_ERROR_SAMPLERATE 		-31
#define IOCTL_ERROR_VOLTAGELEVEL 	-32

#endif
